#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100000, mods=998244353;

long long fact(int n) {
  long long ret=1;
  for (int i=1; i<=n; i++) {
    ret = (ret*i)%mods;
  }
  return ret;
}

long long qpower(long long a, int n) {
  long long s=1;
  for (; n>1; n/=2) {
    if (n%2) {
      s = (s*a)%mods;
    }
    a = (a*a)%mods;
  }
  return s*a%mods;
}

long long solve(int o, int n, int a[]) {
  static int book[maxn+1];
  long long ret=0;
  if (o<=n) {
    for (int i=1; i<=n; i++) {
      if (!book[i]) {
	book[i] = o;
	ret = (ret+solve(o+1, n, a))%mods;
	book[i] = 0;
      }
    }
  } else {
    static int s[maxn+1];
    static bool key[maxn+1];
    for (int i=1; i<=n; i++) {
      key[i] = false;
      s[book[i]] = i;
    }
    for (int i=1; i<=n; i++) {
      if (a[s[i]]==-1 || key[a[s[i]]]) {
	key[s[i]] = true;
	ret++;
      }
    }
  }
  return ret;
}

int main() {
  freopen("treasure.in", "r", stdin);
  freopen("treasure.out", "w", stdout);

  static int a[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }

  printf("%lld", (solve(1, n, a)*qpower(fact(n), mods-2))%mods);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
